<template>
        <Modal :transfer=false  v-model="usersListModal"  :width=900 @on-cancel="modelClose" footer-hide><!--footer-hide-->
        <Form ref="form2" :model="form2" :label-width="80">
            <Row>
                <Col span="8">
                    <FormItem label="姓名:">
                        <Input type="text" v-model="form2.userName" style="width: 100%"></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="机构：">
                        <!--<cascaderDom ref="queryOrgCascader" @setOrgInfo="setOrgId" :orgTree="true"></cascaderDom>-->
                        <Input type="text" v-model="form2.orgName" style="width: 100%"></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <Button icon="md-search" type="error" style="margin-left: 8px" @click="query">查询</Button>
                    <Button @click="reset" style="margin-left: 8px">重置</Button>
                </Col>
            </Row>
        </Form>

        <Table class="table" no-data-text="没有查询到相关数据!"  size="small" :loading="loading"
               highlight-row stripe border :columns="columns1" width="100%" height="400" :data="data1">
        </Table>
        <Page  :page-size="pagedata.pageSize" :total="pagedata.total" :current="pagedata.currentPage" @on-change="pagechange" :page-size-opts="pageSizeArray"
               @on-page-size-change="pageSizeChange" show-total show-sizer show-elevator />
        </Modal>
</template>

<script>
    import {Api} from '../../../api/index.js'
    var cascaderDom = () => import('@/components/cascader-dom.vue');

    export default {
        components: {cascaderDom},
        props:['usersListModal'],
        data() {
            return {
                loading: false,
                buttonLoading:false,
                data1 : this.datas,
                form2:{
                    userName: ''
                },
                //分页参数
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                columns1: [
                    {
                        title: '姓名',
                        minWidth: 100,
                        align: 'center',
                        key: 'userName'
                    },
                    {
                        title: '登录账号',
                        minWidth: 100,
                        align: 'center',
                        key: 'loginId'
                    },
                    {
                        title: '所属单位',
                        minWidth: 250,
                        align: 'center',
                        key: 'companyName'
                    },   {
                        title: '所属部门',
                        minWidth: 250,
                        align: 'center',
                        key: 'orgName'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        minWidth: 140,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '12px'
                                    },
                                    on: {
                                        click: () => {
                                            this.save(params.row);
                                        }
                                    }
                                }, '选择')
                            ]);
                        }
                    }
                ],
                dataTable: [],
                userIds:''
            }
        },
        watch: {
          "usersListModal": function (qw,er) {
              if(!qw){
                  this.form2 = {};
                  this.query();
              }
          }
        },
        mounted: function() {
            this.query();
        },
        methods: {
            modelClose(){
                this.$emit('closeDialog');
            },
            pagechange(pageNum){
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            save(row){
                this.$emit('getSelectData',row);
                this.$emit('closeDialog');
            },
            //查
            query() {
                let data = {
                    fromPage: this.pagedata.currentPage,
                    pageSize: this.pagedata.pageSize
                }
                data = Object.assign(data,JSON.parse(JSON.stringify(this.form2)));
                this.loading = true;
                this.$http.get(Api.queryUser, {params : data}).then(res => {
                    res.data.data.map(i => {
                        if(i.orgInfo != null) {
                            i.orgName = i.orgInfo.orgName;
                            i.orgId = i.orgInfo.orgId;
                            if (i.position != null) {
                                i.positionId = i.position.positionId
                                i.positionName = i.position.positionName
                            }
                        }
                    })
                    this.pagedata.total = res.data.total;
                    this.data1 = res.data.data;
                    this.loading = false;
                }).catch(e => {
                    //this.$Message.error('请求失败');
                })
            },
            reset() {
                this.form2 = {
                    userName: ''
                };
                this.query();
            },
            setOrgId(data) {
                this.form2.orgId = data[data.length - 1];
            }
        }
    }
</script>
